﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using BussinessObjects;
using BusinessObjects;
using LibraryO2S;
using System.IO;
using System.Xml;

public partial class controls_admin_Contact : Pages_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            try
            {
                string fname = Server.MapPath("../upload/xml/contact.xml");
                if (File.Exists(fname))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fname);
                    XmlNode root = doc.DocumentElement;
                    XmlNodeList list = root.ChildNodes;
                    txtGmap.Text = list.Item(0).InnerText;
                    fkcContent.Value = list.Item(1).InnerText;
                }
            }
            catch (Exception ex)
            {
                divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi :<br />" + ex.Message);
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string fname = Server.MapPath("../upload/xml/contact.xml");
            XmlTextWriter xw = new XmlTextWriter(fname, null);
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 6;
            xw.WriteStartDocument();
            xw.WriteStartElement("contact");
            //title
            xw.WriteStartElement("gmap");
            xw.WriteString(txtGmap.Text.Trim());
            xw.WriteEndElement();
            //skype
            xw.WriteStartElement("content");
            xw.WriteString(fkcContent.Value);
            xw.WriteEndElement();
            //yahoo
            xw.WriteEndElement();
            xw.WriteEndDocument();
            xw.Flush();
            xw.Close();
            divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Cập nhật thành công.");
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally { base.CloseConnection(); }
    }
}
